package sandbox;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class OrderedList {
	public static void main(String[] args) {
		List<IntegerStringPair> ispList = new ArrayList<IntegerStringPair>();
		ispList.add(new IntegerStringPair(4, "4th"));
		ispList.add(new IntegerStringPair(1, "1st"));
		ispList.add(new IntegerStringPair(2, "2nd"));
		ispList.add(new IntegerStringPair(3, "3rd"));

		System.out.println("Before sorted");
		for (IntegerStringPair integerStringPair : ispList) {
			System.out.println(integerStringPair.getS());
		}
		Collections.sort(ispList, new IntegerStringPairComparator());
		System.out.println("After sorted");
		for (IntegerStringPair integerStringPair : ispList) {
			System.out.println(integerStringPair.getS());
		}

	}
}

class IntegerStringPairComparator implements Comparator<IntegerStringPair> {
	@Override
	public int compare(IntegerStringPair o1, IntegerStringPair o2) {
		return o1.compareTo(o2);
	}
}

class IntegerStringPair implements Comparable<IntegerStringPair> {
	private Integer i;
	private String s;

	public Integer getI() {
		return i;
	}

	public String getS() {
		return s;
	}

	public IntegerStringPair(Integer i, String s) {
		this.i = i;
		this.s = s;
	}

	@Override
	public int compareTo(IntegerStringPair that) {
		return this.getI().compareTo(that.getI());
	}
}